﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cuba.Consulta;
using Cuba.Consulta.CRN;

public partial class Consulta_ClientZone : System.Web.UI.Page
{
    protected override void InitializeCulture()
    {
        if (!IsPostBack)
        {
            string lang = Request.QueryString["lang"];
            if (string.IsNullOrEmpty(lang))
                return;
            CubaSite.Configuracion.LanguageUtilities.ChangeLanguageFromContext(lang);
        }
        else
            CubaSite.Configuracion.LanguageUtilities.SetLanguageFromContext();
        base.InitializeCulture();
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void ConsultarLinkButton_Click(object sender, EventArgs e)
    {
        ErrorAlert.Visible = false;
        CaptchaError.Text = "";
        if (!Page.IsValid)
        {
            CaptchaError.Text = Resources.ClientZone.CaptchaIncorrecto;
            return;
        }

        string codigo = CodigoServicioTextBox.Text;
        string documento = DocumentoTextBox.Text;

        Consulta objConsulta = null;
        try
        {
            objConsulta = ConsultaCRN.BuscarServicio(codigo, documento);
        }
        catch (Exception ex)
        {
            MensajeError.Text = Resources.ClientZone.ErrorBusqueda;
            ErrorAlert.Visible = true;
            return;
        }
        if (objConsulta == null)
        {
            MensajeError.Text = Resources.ClientZone.TramiteNoEncontrado;
            ErrorAlert.Visible = true;
            return;
        }
        if (objConsulta.TipoServicio.Equals("Tramite"))
        {
            Session["TramiteId"] = objConsulta.ServicioId;
            Response.Redirect(Resources.ClientZone.DetalleTramiteUrl);
        }
    }
}